package springbook.user.dao;

import javax.sql.DataSource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;

//애플리케이션 컨텍스트 또는 빈 팩토리가 사용할 설정정보라는 표시
@Configuration 
public class DaoFactory {
		
	// 오브젝트 생성을 담당하는 IoC용 메소드라는 표시
	@Bean 
	public UserDao UserDaoJdbc() {
				
		//return new UserDao(connectionMaker());
		UserDaoJdbc userDao = new UserDaoJdbc();
		//userDao.setConnectionMaker(countingConnectionMaker());
		userDao.setDataSource(dataSource());
		return userDao;
	}
	@Bean
	public ConnectionMaker countingConnectionMaker(){
		CountingConnectionMaker ccm = new CountingConnectionMaker();
		ccm.setRealConnectionMaker(realConnectionMaker());
		return ccm;
	}	
	
	@Bean
	public ConnectionMaker realConnectionMaker(){
		return new DConnectionMaker(); 
	}
	
	@Bean
	public DataSource dataSource(){
		
		SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
		
		dataSource.setDriverClass(com.mysql.jdbc.Driver.class);
		dataSource.setUrl("jdbc:mysql://localhost/springbook");
		dataSource.setUsername("root");
		dataSource.setPassword("1111");
		
		return dataSource;
	}
}
